package chapter06;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Test05_play {
    public static void main(String[] args) {
        String[] flowers = {"♠","♥","♣","♦"};
        String[] numbers = {"A","2","3","4","5",
                "6","7","8","9","10","J","Q","K"};
        ArrayList<String> cards = new ArrayList<>();
        for (int i=0;i<flowers.length;i++){
            for(int j=0;j<numbers.length;j++){
                cards.add(flowers[i]+numbers[j]);
            }
        }
        Collections.addAll(cards,"大王","小王");
        System.out.println(cards);
        //洗牌
        Collections.shuffle(cards);
        System.out.println(cards);
        ArrayList<String> n1 = new ArrayList<>();
        ArrayList<String> n2 = new ArrayList<>();
        ArrayList<String> n3 = new ArrayList<>();
        //发牌
        for(int i=0;i<17;i++){
            n1.add(cards.get(i));
            n2.add(cards.get(i+17));
            n3.add(cards.get(i+34));
        }
        System.out.println(n1);
        System.out.println(n1.size());
        System.out.println(n2);
        System.out.println(n2.size());
        System.out.println(n3);
        System.out.println(n3.size());
        ArrayList<String> n4 = new ArrayList<>();
        Collections.addAll(n4,cards.get(cards.size()-3),
                cards.get(cards.size()-2),
                cards.get(cards.size()-1));
        System.out.println(n4);
        //进行排序 自定义排序规则
        Collections.sort(n1, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Character.compare(
                        o1.charAt(o1.length()-1),
                        o2.charAt(o2.length()-1));
            }
        });
        System.out.println(n1);
    }
}
